home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2001 August
/
CHIP Turkiye Ağustos 2001.iso
/
prog
/
agustos
/
08
/
setup.exe
/
Favorite.java
< prev
next >
Wrap
Text File
|
2001-06-19
|
12KB
|
317 lines
/* Convert MSIE Favourites to HTML page */
/* Author: Brian D. Jones */
/* Date: 10th Jan 97 */
/* Email: Brian_Jones@technologist.com */
// History: 18 May 97 Check for "URL=" since not always last line in file.
// 14 Jun 97 Long names which include blanks now supported.
// 26 Jul 97 Explorer 4.0 aware
// 13 Oct 97 Explorer 4.0 Outline added.
// 20 Nov 99 Change Web site URL.
// 26 May 2001 Sort entries.
// 26 May 2001 Make like an Applet for use in HTML Application GUI
import java.io.*;
import java.util.*;
import java.applet.*;
import java.awt.*;
import com.ms.security.*;
public class Favorite extends Applet {
public static String Version = "1.81";
private static int level = 0;
private static void ListDir( File Path , PrintStream Out) {
String Names[] = Path.list();
if (folderFirst) sortF(Names, Path);
else sort(Names);
if (level == 0)
Out.println("<div id=\"Out" +level +"\">");
else
Out.println("<div id=\"Out" +level +"d\" style=\"display:None\">");
level = level +1;
Out.println("<DL>");
for (int i=0; i < Names.length; i++) {
try {
File temp = new File( Path, Names[i] );
if ( temp.isDirectory() ) {
Out.println( "<DT><div id=\"Out" +level +"\" class=\"Outline\" style=\"cursor: hand\"><IMG SRC=\"" +iconPath +"urlfldr.gif\" WIDTH=16 HEIGHT=16 id=\"Out" +level +"\" class=\"Outline\" hspace=4> "+ temp.getName() +"</div><DD>" );
ListDir ( temp, Out );
Out.println( "</DD></DT>" );
}
else if (temp.getName().endsWith(".url")) {
try {
String BaseName = temp.getName();
String sURL = null,
sDesc = null,
sAuthor = null,
sWhatsNew = null,
sAccessed = null, sModified = null;
DataInputStream file = new DataInputStream( new FileInputStream( temp ));
String Line= null;
Date dateModified = null,
dateAccessed = null;
while ( file.available() > 0 ) {
Line = file.readLine();
// if (Line.startsWith("URL=")) break; // Not always last line.
if (Line.startsWith("URL="))
sURL = Line.substring( Line.indexOf( "=" )+1);
// These items appeared in the Beta, but don't seem to be in the final version.
if (Line.startsWith("Desc="))
sDesc = Line.substring( Line.indexOf( "=" )+1);
if (Line.startsWith("Author="))
sAuthor = Line.substring( Line.indexOf( "=" )+1);
if (Line.startsWith("WhatsNew="))
sWhatsNew = Line.substring( Line.indexOf( "=" )+1);
if (Line.startsWith("Accessed="))
sAccessed = Line.substring( Line.indexOf( "=" )+1);
if (Line.startsWith("Modified="))
sModified = Line.substring( Line.indexOf( "=" )+1);
}
file.close();
// Line = Line.substring( Line.indexOf( "=" )+1);
BaseName = BaseName.substring( 0, BaseName.lastIndexOf( "." ));
Out.print( "<DT>");
try {
if (sModified != null) {
String tmp = null;
StringTokenizer token = new StringTokenizer( sModified, ",", false );
tmp = token.nextToken().substring(2);
dateModified = new Date( Long.parseLong(tmp,16));
// Out.println(" Modified: " +dateModified.toLocaleString());
}
if (sAccessed != null) {
String tmp = null;
StringTokenizer token = new StringTokenizer( sAccessed, ",", false );
tmp = token.nextToken().substring(2);
dateAccessed = new Date( Long.parseLong(tmp,16));
// Out.println(" Modified: " +dateAccessed.toLocaleString());
}
}
catch ( Exception e ) { } // Out.println( "<!-- " +e +" -->");}
Out.print( "<A HREF=\"" +sURL +"\">");
if ( dateAccessed != null
&& dateModified != null
&& dateAccessed.after(dateModified))
Out.print( "<IMG SRC=\"" + iconPath + "urlchg.gif\" WIDTH=16 HEIGHT=16 border=0 hspace=4>");
else
Out.print( "<IMG SRC=\"" + iconPath + "url.gif\" WIDTH=16 HEIGHT=16 Border=0 hspace=4>");
Out.println( BaseName +"</A>");
if (sWhatsNew != null)
Out.println("<DD>What's new: " +sWhatsNew +"</DD>");
else if (sDesc != null )
Out.println("<DD>" +sDesc +"</DD>");
}
catch ( Exception e ) { ;
}
}
else if (temp.getName().equalsIgnoreCase("desktop.ini")) {
try {
String BaseName = Path.getName();
String sURL = null,
sLogo = "" + iconPath +"url.gif",
sWideLogo = null;
DataInputStream file = new DataInputStream( new FileInputStream( temp ));
String Line= null;
while ( file.available() > 0 ) {
Line = file.readLine();
// if (Line.startsWith("URL=")) break; // Not always last line.
if (Line.startsWith("CDFURL="))
sURL = Line.substring( Line.indexOf( "=" )+1);
if (Line.startsWith("Logo="))
sLogo = Line.substring( Line.indexOf( "=" )+1);
if (Line.startsWith("WideLogo="))
sWideLogo = Line.substring( Line.indexOf( "=" )+1);
}
file.close();
if (sURL != null) {
Out.print( "<A HREF=\"" +sURL +"\">");
if (sWideLogo != null)
Out.print( "<IMG SRC=\"" +sWideLogo +"\"></A>");
else
Out.print( "<IMG SRC=\"" +sLogo +"\"></A>");
}
}
catch ( Exception e ) { ;
}
}
}
catch ( Exception e ) { continue;
}
}
Out.println("<P></DL>");
Out.println("</div>");
}
public static void DoIt( String Path, PrintStream Out ) {
File Root = null;
try {
Root = new File( Path );
}
catch ( Exception e ) {
Out.println("<HTML><HEAD><TITLE>404 Not Given</TITLE></HEAD>");
Out.println("<BODY><H1>404 Not Given</H1>No path was requested.<P></BODY></HTML>");
return;
}
if ( !Root.exists()
|| !Root.isDirectory()) {
Out.println("<HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD>");
Out.println("<BODY><H1>404 Not Found</H1>The requested path <EM>" +Path +"</EM> was not found on this server<P></BODY></HTML>");
return;
}
Out.print( "<HTML><HEAD>");
Out.println( "<TITLE>" +Root.getName() +"</TITLE>");
Out.println("<script language=\"JavaScript\">");
Out.println("<!--");
Out.println("function clickHandler() {");
Out.println(" var targetId, srcElement, targetElement;");
Out.println(" if (window.event) srcElement = window.event.srcElement;");
Out.println(" else srcElement = clickHandler.arguments[0].target;");
Out.println(" if (srcElement.className == \"Outline\") {");
Out.println(" targetId = srcElement.id + \"d\";");
Out.println(" if (document.getElementById) targetElement = document.getElementById(targetId);");
Out.println(" else if (document.all) targetElement = document.all(targetId);");
Out.println(" else return;");
Out.println(" if (targetElement.style.display == \"none\") {");
Out.println(" targetElement.style.display = \"\";");
Out.println(" document.images(srcElement.id).src = \"" + iconPath + "urlfldro.gif\";");
Out.println(" setCookie( targetId, \"show\" );");
Out.println(" } else {");
Out.println(" targetElement.style.display = \"none\";");
Out.println(" document.images(srcElement.id).src = \"" + iconPath + "urlfldr.gif\";");
Out.println(" setCookie( targetId, \"none\" );");
Out.println(" }");
Out.println(" }");
Out.println("}");
Out.println("");
Out.println("function setCookie(name, value) {");
Out.println(" document.cookie = name + \"=\" + escape(value);");
Out.println("}");
Out.println("function readtree() {");
Out.println(" var dc = document.cookie;");
Out.println(" if (dc.length > 0) {");
Out.println(" ca = dc.split(\";\");");
Out.println(" for ( c in ca ) {");
Out.println(" mid = ca[c].indexOf(\"=\");");
Out.println(" if (ca[c].charAt(0) == \" \") targetId = ca[c].substring(1,mid)");
Out.println(" else targetId = ca[c].substring(0,mid)");
Out.println(" if ( targetId.substr(0,3) != \"Out\") continue;");
Out.println(" val = ca[c].substr(mid+1,4);");
Out.println(" if (document.getElementById) targetElement = document.getElementById(targetId);");
Out.println(" else if (document.all) targetElement = document.all(targetId);");
Out.println(" else return;");
Out.println(" if (val == \"show\") {");
Out.println(" targetElement.style.display = \"\";");
Out.println(" document.images(targetId.substr(0,targetId.length-1)).src = \"" + iconPath + "urlfldro.gif\";");
Out.println(" }");
Out.println(" }");
Out.println(" }");
Out.println("}");
Out.println("document.onclick = clickHandler;");
Out.println("//-->");
Out.println("</script>");
Out.println( "<style type=\"text/css\">");
Out.println(" body { font-family: \"verdana,arial,helvetica\"; font-size:10pt;}");
Out.println(" .head { font-size:14pt; font-weight: bold;}");
Out.println(" .OutLine { font-weight: bold; }");
Out.println("</style>");
Out.println( "</HEAD>" );
Out.print("<body onload=\"readtree();\">");
Out.println( "<div class=\"head\"><IMG SRC=\"" + iconPath + "urlfldr.gif\" WIDTH=32 HEIGHT=32>" +Root.getName() +"</div><HR>");
ListDir( Root, Out );
Out.println( "<HR>" );
Out.println( "Created: " +new Date().toLocaleString() );
Out.println( "using Java application v: " + Version + " created by <A HREF=\"http://www.jonessoft.free-online.co.uk\">Brian D. Jones</A>" );
Out.println( "<A HREF=\"mailto:Brian_Jones@technologist.com\">Email: Brian_Jones@technologist.com</A>" );
Out.println( "</BODY>" );
Out.println( "</HTML>" );
}
private static String cmdLine( String args[]) {
String returnString = args[0];
for ( int i=1; i< args.length; i++) returnString = returnString +" " +args[i];
return returnString;
}
private static boolean folderFirst = false;
private static String iconPath = "/icons/";
private static void sort( String toSort[]) {
if (toSort.length<2) return;
int i,j;
for (i=0; i < toSort.length ; i++)
for (j=i+1; j < toSort.length ; j++)
if (toSort[j].compareTo(toSort[i])< 0) {
String temp = toSort[i];
toSort[i] = toSort[j];
toSort[j] = temp;
}
}
private static void sortF( String toSort[], File Path) {
if (toSort.length<2) return;
int i,j;
for (i=0; i < toSort.length ; i++) {
File fileA = new File( Path, toSort[i] );
for (j=i+1; j < toSort.length ; j++) {
File fileB = new File( Path, toSort[j]);
if ( (fileB.isDirectory() && fileA.isFile() )
|| ( ((fileA.isDirectory() && fileB.isDirectory() )
|| (fileA.isFile() && fileB.isFile()) )
&& (toSort[j].compareTo(toSort[i])< 0) ) ) {
String temp = toSort[i];
toSort[i] = toSort[j];
toSort[j] = temp;
fileA = fileB;
}
}
}
}
public void init()
{
setForeground( Color.black );
setBackground( Color.green );
}
public void setOrder( boolean order ) {
folderFirst = order;
}
public void setPath( String Path ) {
if (Path==null) iconPath = "";
else iconPath = Path.replace('\\','/');
}
public void save(String folder, String toFile) {
PolicyEngine.assertPermission(PermissionID.SYSTEM);
FileOutputStream saveFile = null;
level = 0;
try {
saveFile = new FileOutputStream (toFile) ;
DoIt( folder, new PrintStream( saveFile ));
saveFile.close();
} catch (Exception e) {}
}
public static void main (String args[] ) {
System.out.println("Content-type: text/html");
System.out.println("");
if (args.length < 1) {
System.out.println("<HTML><HEAD><TITLE>404 Not Given</TITLE></HEAD>");
System.out.println("<BODY><H1>404 Not Given</H1>No path was requested.<P></BODY></HTML>");
return;
}
DoIt( cmdLine( args ), System.out );
}
}